package io.xccit.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.xccit.pojo.param.ProductCollectParam;
import io.xccit.pojo.param.ProductIDParam;
import io.xccit.pojo.product.Product;
import io.xccit.result.AjaxResult;
import io.xccit.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author CH_ywx
 * @date 2023-09-18
 * @description 购物车调用商品Controller
 */
@Api(tags = "购物车调用商品接口")
@RestController
@RequestMapping("/product")
public class ProductCartController {

    @Autowired
    private IProductService productService;

    @ApiOperation("根据商品ID获取商品详情")
    @PostMapping("/cart/detail")
    public Product getDetail(@RequestBody ProductIDParam productIDParam){
        AjaxResult detail = productService.detail(productIDParam.getProductID());
        Product product = (Product)detail.getData();
        return product;
    }

    @ApiOperation("获取购物车商品集合")
    @PostMapping("/cart/list")
    public List<Product> cartProductList(@RequestBody ProductCollectParam productCollectParam){
        return productService.cartProductList(productCollectParam.getProductIds());
    }
}
